package com.wu.util.spider.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author 50816
 */
@Configuration
public class TaskPoolConfig {

    @Autowired
    SpiderConfiguration spiderConfiguration;

    @Bean("taskExecutor")
    public Executor taskExecutro(){
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(spiderConfiguration.getPollCoreTheadSize());
        taskExecutor.setMaxPoolSize(spiderConfiguration.getPollMaxTheadSize());
        taskExecutor.setQueueCapacity(spiderConfiguration.getPollQueueSize());
        taskExecutor.setKeepAliveSeconds(60);
        taskExecutor.setThreadNamePrefix(spiderConfiguration.getPollTheadBaseName());
        taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
        taskExecutor.setAwaitTerminationSeconds(60);
        return taskExecutor;
    }


}